<?php
require './封装.php';
$str=[
    'host'=>'127.0.0.1',
    'root'=>'root',
    'pwd'=>'root',
    'dbname'=>'db'
];
$DB=new Db($str);
// var_dump($DB);
$sql="select count(*) from products";
$total=$DB->select($sql)[0][0];

$size=10;

$totalPage=ceil($total/$size);

$currentPage=1;
$start=($currentPage-1)*$size;
$sql="select * from products limit $start,$size";
$data=$DB->select($sql);
// for($i=1;$i<=$totalPage;$i++){
//     echo $i;
// }


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
    table{
        width: 780px;
        border: solid #000 1px;
        border-collapse: collapse;
    }
    td,th{
        border: solid #000 1px;
    }
    </style>
</head>
<body>
<table>
    <tr>
        <th>编号</th>
        <th>商品名称</th>
        <th>规格</th>
        <th>价格</th>
    </tr>
    <?php foreach($data as $item): ?>
    <tr>
        <td><?=$item[0]?></td>
        <td><?=$item[1]?></td>
        <td><?=$item[2]?></td>
        <td><?=$item[3]?></td>
    </tr>
    <?php endforeach;?>
</table>
</body>
</html>

<?php
for($i=1;$i<=$totalPage;$i++){
    echo '<a href="./分页.php?currentPage={$i}">'.$i.'</a>';
}

?>